//
//  YLRiskAssessmentViewModel.m
//  YLFinanceService
//
//  Created by she1323 on 2017/9/20.
//  Copyright © 2017年 she1323. All rights reserved.
//

#import "YLRiskAssessmentViewModel.h"
#import "WHNetworkTool.h"
#import "WHProgressHUD.h"
#import "YLAccountTool.h"
#import "YLRiskAssessmentAnswerModel.h"
#import <YYModel.h>
@implementation YLRiskAssessmentViewModel

- (NSArray<YLRiskAssessmentGroup *> *)groups
{
    if (!_groups) {
        NSMutableArray *arr = [NSMutableArray array];
        
        {
            YLRiskAssessmentGroup *group = [[YLRiskAssessmentGroup alloc] init];
            group.title = @"您的年龄介于";
            group.titleNumber = 1;
            group.models = @[[YLRiskAssessmentModel modelWithIndex:1 content:@"18-30岁"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"31-50岁"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"51-65岁"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"高于65岁"]];
            [arr addObject:group];
        }
        
        {
            YLRiskAssessmentGroup *group = [[YLRiskAssessmentGroup alloc] init];
            group.title = @"您的学历";
            group.titleNumber = 2;
            group.models = @[[YLRiskAssessmentModel modelWithIndex:1 content:@"高中及以下"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"中专或大专"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"本科"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"硕士及以上"]];
            [arr addObject:group];
        }
        
        {
            YLRiskAssessmentGroup *group = [[YLRiskAssessmentGroup alloc] init];
            group.title = @"您的职业为";
            group.titleNumber = 3;
            group.models = @[[YLRiskAssessmentModel modelWithIndex:1 content:@"无固定职业"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"专业技术人员"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"一般企事业单位员工"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"金融行业一般从业人员"]];
            [arr addObject:group];
        }

        {
            YLRiskAssessmentGroup *group = [[YLRiskAssessmentGroup alloc] init];
            group.title = @"您的主要收入来源是";
            group.titleNumber = 4;
            group.models = @[[YLRiskAssessmentModel modelWithIndex:1 content:@"工资、劳务报酬"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"生产经营所得"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"利息、股息、转让等金融性资产收入"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"无固定收入"]];
            [arr addObject:group];
        }
        
        {
            YLRiskAssessmentGroup *group = [[YLRiskAssessmentGroup alloc] init];
            group.title = @"您的家庭可支配年收入为（折合人民币）?";
            group.titleNumber = 5;
            group.models = @[[YLRiskAssessmentModel modelWithIndex:1 content:@"50 万元以下"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"50—100 万元"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"100—500 万元"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"500—1000 万元"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"1000 万元以上"]
                             ];
            [arr addObject:group];
        }
        
        {
            YLRiskAssessmentGroup *group = [[YLRiskAssessmentGroup alloc] init];
            group.title = @"在您每年的家庭可支配收入中，可用于金融投资（储蓄存款除外）的比例为";
            group.titleNumber = 6;
            group.models = @[[YLRiskAssessmentModel modelWithIndex:1 content:@"小于 10%"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"10% 至 25%"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"25% 至 50%"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"大于 50%"]];
            [arr addObject:group];
        }
        
        {
            YLRiskAssessmentGroup *group = [[YLRiskAssessmentGroup alloc] init];
            group.title = @"您是否有尚未清偿的数额较大的债务，如有，其性质是";
            group.titleNumber = 7;
            group.models = @[[YLRiskAssessmentModel modelWithIndex:1 content:@"没有"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"有，住房抵押贷款等长期定额债务"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"有，信用卡欠款、消费信贷等短期信用债务"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"有，亲戚朋友借款"]];
            [arr addObject:group];
        }
        
        {
            YLRiskAssessmentGroup *group = [[YLRiskAssessmentGroup alloc] init];
            group.title = @"您的投资知识可描述为：";
            group.titleNumber = 8;
            group.models = @[[YLRiskAssessmentModel modelWithIndex:1 content:@"有限：基本没有金融产品方面的知识"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"一般：对金融产品及其相关风险具有基本知识的和理解"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"丰富：对金融产品及其相关风险具有丰富的知识和理解"]];
            [arr addObject:group];
        }
        
        {
            YLRiskAssessmentGroup *group = [[YLRiskAssessmentGroup alloc] init];
            group.title = @"您的投资经验可描述为：";
            group.titleNumber = 9;
            group.models = @[[YLRiskAssessmentModel modelWithIndex:1 content:@"除银行储蓄外，基本没有其他投资经验"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"购买过债券、保险等理财产品"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"参与过股票、基金等产品的交易"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"参与过权证、期货、期权等产品的交易"]];
            [arr addObject:group];
        }

        {
            YLRiskAssessmentGroup *group = [[YLRiskAssessmentGroup alloc] init];
            group.title = @"您有多少年投资基金、股票、信托、私募证券或金融衍生产品等风险投资品的经验？";
            group.titleNumber = 10;
            group.models = @[[YLRiskAssessmentModel modelWithIndex:1 content:@"没有经验"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"少于 2 年"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"2 至 5 年"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"5 至 10 年"],
                              [YLRiskAssessmentModel modelWithIndex:1 content:@"10 年以上"]];
            [arr addObject:group];
        }
        
        {
            YLRiskAssessmentGroup *group = [[YLRiskAssessmentGroup alloc] init];
            group.title = @"您计划的投资期限是多久?";
            group.titleNumber = 11;
            group.models = @[[YLRiskAssessmentModel modelWithIndex:1 content:@"1 年以下"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"1 至 3 年"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"3 至 5 年"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"5 年以上"]];
            [arr addObject:group];
        }
        
        {
            YLRiskAssessmentGroup *group = [[YLRiskAssessmentGroup alloc] init];
            group.title = @"您打算重点投资于哪些种类的投资品种?";
            group.titleNumber = 12;
            group.models = @[[YLRiskAssessmentModel modelWithIndex:1 content:@"债券、货币市场基金、债券基金等固定收益类投资品种"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"股票、混合型基金、股票型基金等权益类投资品种"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"期货、期权等金融衍生品"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"其他产品或者服务"]];
            [arr addObject:group];
        }
        
        {
            YLRiskAssessmentGroup *group = [[YLRiskAssessmentGroup alloc] init];
            group.title = @"以下哪项描述最符合您的投资态度？";
            group.titleNumber = 13;
            group.models = @[[YLRiskAssessmentModel modelWithIndex:1 content:@"厌恶风险，不希望本金损失，希望获得稳定回报"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"保守投资，不希望本金损失，愿意承担一定幅度的收益波动"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"寻求资金的较高收益和成长性，愿意为此承担有限本金损失"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"希望赚取高回报，愿意为此承担较大本金损失"]];
            [arr addObject:group];
        }

        {
            YLRiskAssessmentGroup *group = [[YLRiskAssessmentGroup alloc] init];
            group.title = @"假设有两种投资：投资A预期获得10% 的收益，可能承担的损失非常小；投资B预期获得30% 的收益，但可能承担较大亏损。您会怎么支配您的投资";
            group.titleNumber = 14;
            group.models = @[[YLRiskAssessmentModel modelWithIndex:1 content:@"全部投资于收益较小且风险较小的A"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"同时投资于A和B，但大部分资金投资于收益较小且风险较小的A"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"同时投资于A 和B，但大部分资金投资于收益较大且风险较大的B"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"全部投资于收益较大且风险较大的B"]];
            [arr addObject:group];
        }
        
        {
            YLRiskAssessmentGroup *group = [[YLRiskAssessmentGroup alloc] init];
            group.title = @"您认为自己能承受的最大投资损失是多少？";
            group.titleNumber = 15;
            group.models = @[[YLRiskAssessmentModel modelWithIndex:1 content:@"10%以内"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"10%-30%"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"30%-50%"],
                             [YLRiskAssessmentModel modelWithIndex:1 content:@"超过 50%"]];
            [arr addObject:group];
        }

        
        _groups = arr;
        
    }
    return _groups;
}

- (RACCommand *)summitCommand
{
    if (!_summitCommand) {
        __weak typeof(self) weakSelf = self;
        _summitCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            
          return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        
              
              NSMutableDictionary *param = [NSMutableDictionary dictionaryWithCapacity:3];
            
              param[@"Answer"] = input;
              
              NSString *url = [NSString stringWithFormat: @"%@Product/FundRiskEvaluation", YLURL];
                [WHProgressHUD showStatus:@"正在评测中... 请勿退出"];
                [[WHNetworkTool shareInstance] sendPostWithUrl:url header:[YLAccountTool header] params:param success:^(id responseObject) {
                    [WHProgressHUD dismiss];
                    
                    
                    if ([responseObject[@"httpCode"] integerValue] == 200) {
                        YLRiskAssessmentAnswerModel *answerModel = [YLRiskAssessmentAnswerModel yy_modelWithDictionary:responseObject[@"httpResult"]];
                        weakSelf.anseweModel = answerModel;
                        [subscriber sendNext:nil];

                    } else {
                        [WHProgressHUD showError:responseObject[@"message"]];
                        [weakSelf.wh_loadDataErrorSubject sendNext:nil];
                    }

                    [subscriber sendCompleted];

                } fail:^(NSError *error) {
                     [weakSelf.wh_loadDataErrorSubject sendNext:nil];
                     [subscriber sendCompleted];
                }];
              

                
                
                return nil;
            }];
            
        }];
    }
    return _summitCommand;
}

// 数组转json
- (NSString *)toJSONData:(id)theData
{
    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:theData options:NSJSONWritingPrettyPrinted error:nil];
    
    if ([jsonData length]&&error== nil){
        
        return [[NSString alloc] initWithData:jsonData
                                     encoding:NSUTF8StringEncoding];
    }else{
        return nil;
    }
}
@end
